library Saline initializer init


	private function SteroidsConditions takes nothing returns boolean
		local integer i = GetSpellAbilityId()
		return i=='A019' or i=='Ablo' or i=='A00Y' or i=='A03T'
	endfunction

	private function Steroids takes nothing returns nothing
		local integer i = 1
		local unit u = GetTriggerUnit()
		local unit u2 = GetSpellTargetUnit()
		local player p = GetOwningPlayer(u)
		local player p2 = GetOwningPlayer(u2)
		
		local integer saline = GetUnitAbilityLevel(u,'A019')
		if GetSpellAbilityId()=='A019' and saline>2 then //Saline IV
			loop
				exitwhen i>3
				call UnitRemoveAbility(u,'B00A') //Open Wounds
				set i=i+1
			endloop
			if saline>4 then //Basic Poisons
				call UnitRemoveAbility(u,'Bpoi')
				call UnitRemoveAbility(u,'Bpsd')
			endif
			if saline>6 then //Moderate Poisons
				call UnitRemoveAbility(u,'B008')
				call UnitRemoveAbility(u,'B00B')
			endif
		elseif GetSpellAbilityId()=='A03T' then //Mini-Saline
			call UnitRemoveAbility(u,'Bpoi')
			call UnitRemoveAbility(u,'Bpsd')
		endif
		if (IsUnitType(u2,UNIT_TYPE_HERO)==true and GetUnitTypeId(u2)!='H002') or (GetUnitPointValue(u2)==12 and GetUnitTypeId(u2)!='z001') then
			call PolledWait(0.25)
			if GetLocalPlayer() == p then
				call StartSound(gg_snd_Steroids)
			endif
			if GetLocalPlayer() == p2 then
				call StartSound(gg_snd_Steroids)
			endif
		endif
		set u = null
		set u2 = null
		set p = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
		call TriggerAddCondition(t,Condition(function SteroidsConditions))
		call TriggerAddAction(t,function Steroids)
	endfunction


endlibrary
